/*
 * @Author: your name
 * @Date: 2021-10-09 14:39:41
 * @LastEditTime: 2021-11-10 10:27:22
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \epet_back\utils\query.js
 */
const mysql = require('mysql2')

// 创建连接池对象
const pool = mysql.createPool({
    host: '127.0.0.1',   //
    port: '3306',
    user: 'root',
    password: '1107302052',
    database: 'lianjie'
})

// 利用Promise封装数据库查询query函数
const query = (sqlStr,params) =>{
    return new Promise((resolve,reject) => {
        pool.query(sqlStr,params,(err,result) => {
            if(err){
                reject(err)
            }else{
                resolve(result)
            }
        })
    })
}

module.exports = query;